WGET?=wget
TAR?=tar
ZIP?=zip
 
SFC_BUNDLE=xfucik03
SFC_BUNDLE_ZIP=$(SFC_BUNDLE).zip
SFC_BUNDLE_CONTENT=CMakeLists.txt Makefile constants.cpp main.cpp main.h wall.h wall.cpp
 
GALIB_DIR=galib247
GALIB_TGZ=$(GALIB_DIR).tgz
GALIB_URL="http://lancet.mit.edu/ga/dist/$(GALIB_TGZ)"
GALIB_LIB=$(GALIB_DIR)/ga/libga.a
 
PUGIXML_DIR=pugixml-1.2
PUGIXML_TGZ=$(PUGIXML_DIR).tar.gz
PUGIXML_URL="http://pugixml.googlecode.com/files/$(PUGIXML_TGZ)"

.PHONY: all build_dir clean distclean galib $(SFC_BUNDLE_ZIP)
 
all: build_dir
	$(MAKE) all -C build
 
build_dir: $(GALIB_LIB)
	test -f $(PUGIXML_TGZ) || $(WGET) $(PUGIXML_URL)
	test -d $(PUGIXML_DIR) || mkdir $(PUGIXML_DIR)
	$(TAR) xzvf $(PUGIXML_TGZ) -C $(PUGIXML_DIR)
	test -d build || mkdir build
	test -d results || mkdir results
	cd build && cmake -D GALIB_DIR=../$(GALIB_DIR) ..
 
$(GALIB_LIB): galib
galib: $(GALIB_DIR)
	$(MAKE) lib -C $(GALIB_DIR)
 
$(GALIB_DIR):
	test -f $(GALIB_TGZ) || $(WGET) $(GALIB_URL)
	$(TAR) xzvf $(GALIB_TGZ)
 
clean:
	rm -rfv build
	rm -rfv results
	#$(MAKE) clean -C doc
 
distclean: clean
	rm -rfv $(GALIB_DIR) $(GALIB_TGZ)
	rm -rfv $(PUGIXML_DIR) $(PUGIXML_TGZ)
	rm -rfv $(SFC_BUNDLE) $(SFC_BUNDLE_ZIP)
 
$(SFC_BUNDLE_ZIP): distclean
	$(ZIP) -r $@ . -x \*~ \*.user \.git\*
